var {
  randomUtils,
  textUtils,
  logUtils,
  clickContent,
  existOneContent,
} = require("../../utils/index");
var adCommon = require("../adCommon");
var adType1 = require("./adType1");
var adType2 = require("./adType2");
var MAX_AD_INTERVAL = 45;
module.exports = {
  startWatchAd(maxAdCount) {
    adCommon.adCount = 0;
    adCommon.maxAdCount = maxAdCount || 20;
    this.normal = true;
    this.getAdType();
  },
  getAdType() {
    var span = randomUtils.getRandom(MAX_AD_INTERVAL, MAX_AD_INTERVAL + 5);
    for (var index = 0; index < 5; index++) {
      sleep(2 * 1000);
      var contents = ["反馈"];
      var result = existOneContent(contents);
      if (result) {
        var text$ =
          result.type == 0 ? result.result.text() : result.result.text;
        logUtils.info("adType 1:", text$);
        adType2.watchAd(span, () => {
          this.getAdType();
        });
        return;
      }
      // sleep(2 * 1000);
      // var contents = ["广告"];
      // var result = existOneContent(contents);
      // if (result) {
      //   var text$ =
      //     result.type == 0 ? result.result.text() : result.result.text;
      //   logUtils.info("adType 2", text$);
      //   adType1.watchAd(span, () => {
      //     this.getAdType();
      //   });
      //   return;
      // }
    }
    logUtils.info("youShi", "未知的adType");
    this.normal = false;
  },
};
